<template>
  <div>
    <div class="success-msg-box">
      <div class="success-img"></div>
      <div class="success-msg">
        <div class="title">
          恭喜您，简历创建完成!您可以申请职位了~
        </div>
        <router-link to="/index/resume-list">
          <div class="tip">继续完善简历，提高求职竞争力</div>
        </router-link>
        <router-link to="/index">
          <div class="tip last">返回首页</div>
        </router-link>
      </div>
    </div>
    <Recommend :recommenid="RecommenId"></Recommend>
    <el-dialog class="psd-dialog" title="设置密码" :visible.sync="dialogVisible" width="480px">
      <div class="notice">如不设置密码可用短信登录，也可稍后在个人中心设置密码</div>
      <el-form :model="form" class="psd-form" label-width="0" :rules="rules" ref="form">
        <el-form-item label="" prop="psd">
          <el-input v-model="form.psd" placeholder="密码" show-password></el-input>
        </el-form-item>
        <el-form-item label="" prop="confirmPsd">
          <el-input v-model="form.confirmPsd" placeholder="确认密码" show-password></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">稍后设置</el-button>
        <el-button type="primary" @click="submit('form')">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import { encrypt } from '../../../utils/unitFile';
import { updatePsd } from '../../../api/registerInfo.js';
// 根据求职意向为您推荐
import Recommend from '@/components/page/components/home_Recommend';
export default {
  data () {
    let validatePass = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请输入密码'));
      } else {
        if (this.form.confirmPsd !== '') {
          this.$refs.form.validateField('confirmPsd');
        }
        callback();
      }
    };
    let validatePass2 = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请再次输入密码'));
      } else if (value !== this.form.psd) {
        callback(new Error('两次输入密码不一致'));
      } else {
        callback();
      }
    };
    return {
      RecommenId: '',
      dialogVisible: true,
      form: {
        psd: '',
        comfirmPsd: ''
      },
      rules: {
        psd: [
          { required: true, message: '请输入密码', trigger: 'blur' },
          { pattern: /^[0-9a-zA-Z_]{6,20}$/, message: '密码由数字、字母或下划线组成' },
          { validator: validatePass, trigger: 'change' },
        ],
        confirmPsd: [
          { required: true, message: '请确认密码', trigger: 'blur' },
          { pattern: /^[0-9a-zA-Z_]{6,20}$/, message: '密码由长度为6-20的数字、字母或下划线组成' },
          { validator: validatePass2, trigger: 'change' }
        ]
      }
    };
  },
  props: {
    resume: {
      type: '',
      default: ''
    }
  },
  components: {
    Recommend
  },
  created () {

  },
  methods: {
    submit (formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          let query = { password: encrypt(this.form.psd) };
          updatePsd(query).then(res => {
            if (res.success) {
              this.dialogVisible = false;
              this.$notify({
                type: "success",
                message: "设置成功"
              });
            } else {
              this.$message.error(`${res.msg}`);
            }
          });
        } else {
          return false;
        }
      });
    }
  },
  watch: {
    resume: {
      handler (newId, oldId) {
        // id 变化更新简历
        if (newId) {
          this.RecommenId = newId;
        }
      },
      immediate: true
    }
  }
};
</script>

<style lang="css" scoped>
.success-msg-box {
    width: 100%;
    /* height: 120px;*/
    height: 400px;
    background: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
}
.success-img {
    width: 66px;
    height: 77px;
    background: url('../../../assets/img/file.png');
    margin-right: 20px;
}
.success > div {
    display: flex;
}
.title {
    font-size: 20px;
    color: #333333;
    font-weight: bold;
    /*   margin-bottom: 4px;*/
    margin-bottom: 20px;
}
.tip {
    /* margin-bottom: 4px;*/
    margin-bottom: 20px;
    font-size: 14px;
    color: #1893fc;
    cursor: pointer;
}
.tip.last {
    margin-bottom: 0;
}
.notice {
    height: 35px;
    font-size: 12px;
    color: #757575;
    background: #f2f7f9;
    text-align: center;
    line-height: 35px;
}
.psd-form {
    width: 100%;
    padding: 28px 58px;
}
.el-input {
    width: 373px;
    height: 44px;
}
</style>